unit NTCustomDataControls;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DB;

type

  { TNTMemDataSet }

  TNTMemDataSet = class(TDataSet)
  private
    FMasterLink: TMasterDataLink;
    function GetMasterFields: String;
    function GetMasterSource: TDataSource;
    function GetVersion: String;
    procedure SetMasterFields(const AValue: String);
    procedure SetMasterSource(const AValue: TDataSource);
    procedure SetVersion(const AValue: String);
    { Private declarations }
  protected
    { Protected declarations }
    { inherited from TDataSet }
    function  GetRecord(Buffer: PChar; GetMode: TGetMode; DoCheck: Boolean): TGetResult; override;
    procedure InternalClose; override;
    procedure InternalOpen; override;
    procedure InternalInitFieldDefs; override;
    function  IsCursorOpen: Boolean; override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property MasterSource: TDataSource read GetMasterSource write SetMasterSource;
    property MasterFields: String read GetMasterFields write SetMasterFields;
    property Version: String read GetVersion write SetVersion stored False;

    { inherited from TDataSet }
    property Active;
    property AutoCalcFields;
    property DataSource;
    property FieldDefs;
    property Fields;
    property Filter;
    property Filtered;
    property BeforeOpen;
    property AfterOpen;
    property BeforeClose;
    property AfterClose;
    property BeforeInsert;
    property AfterInsert;
    property BeforeEdit;
    property AfterEdit;
    property BeforePost;
    property AfterPost;
    property BeforeCancel;
    property AfterCancel;
    property BeforeDelete;
    property AfterDelete;
    property BeforeScroll;
    property AfterScroll;
    property BeforeRefresh;
    property AfterRefresh;
    property OnCalcFields;
    property OnDeleteError;
    property OnEditError;
    property OnFilterRecord;
    property OnNewRecord;
    property OnPostError;
  end;

implementation

{ TNTMemDataSet }

function TNTMemDataSet.GetVersion: String;
begin
  Result := '1.0.0.1';
end;

function TNTMemDataSet.GetMasterFields: String;
begin
  Result := FMasterLink.FieldNames;
end;

function TNTMemDataSet.GetMasterSource: TDataSource;
begin
  Result := FMasterLink.DataSource;
end;

procedure TNTMemDataSet.SetMasterFields(const AValue: String);
begin
  FMasterLink.FieldNames := AValue;
end;

procedure TNTMemDataSet.SetMasterSource(const AValue: TDataSource);
begin
  FMasterLink.DataSource := AValue;
end;

procedure TNTMemDataSet.SetVersion(const AValue: String);
begin
  //TODO
end;

function TNTMemDataSet.GetRecord(Buffer: PChar; GetMode: TGetMode; DoCheck:
  Boolean): TGetResult;
begin
  Result := grOK;
end;

procedure TNTMemDataSet.InternalClose;
begin
  if DefaultFields then
    DestroyFields;
  //FRecordCount := 0;
end;

procedure TNTMemDataSet.InternalOpen;
begin
  if DefaultFields then
    CreateFields;
  BindFields(True);
end;

procedure TNTMemDataSet.InternalInitFieldDefs;
begin
  //inherited;
end;

function TNTMemDataSet.IsCursorOpen: Boolean;
begin
  Result := False;
end;

constructor TNTMemDataSet.Create(AOwner: TComponent);
begin
  FMasterLink := TMasterDataLink.Create(Self);
  inherited Create(AOwner);
end;

destructor TNTMemDataSet.Destroy;
begin
  inherited Destroy;
  FMasterLink.Destroy;
end;

end.
